<template>
  <div @click="getDetail">测试</div>
  <div v-for="item in list">
    <div @click="readFile(item.name)">{{ item.name }}</div>
  </div>
  <div id="file-content"></div>
</template>

<script setup>
import { getReadFolder,readFileContent } from '@/utils/tool'

const list = ref([])
const folderPath = 'D:/测试一下' // 替换为要读取的文件夹路径
    async function getDetail() {
  // 请求主进程读取文件夹
  const result = await getReadFolder(folderPath)
  list.value = result
  console.log('[ result ] >', result)
}

// 读取文件
async function readFile(name) {
  const filePath = `${folderPath}/${name}` // 替换为要读取的文件路径
  // 请求主进程读取文件
  const result = await readFileContent(filePath)
  if (result.success) {
    console.log('File content:', result.content)
    document.getElementById('file-content').textContent = result.content
  } else {
    console.error('Error reading file:', result.error)
  }
}
</script>